package com.bjpowernode.crm.service.impl;

import com.bjpowernode.crm.mapper.QxMapper;
import com.bjpowernode.crm.pojo.Page;
import com.bjpowernode.crm.pojo.Role;
import com.bjpowernode.crm.service.QxService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class QxServiceImpl implements QxService {
    @Resource
    private QxMapper qxMapper;

    @Override
    public void getAllRole(Page page) {
       //在业务逻辑层：给page的总页数totalPage赋值，
        //查询总记录数：
        Integer total = qxMapper.getTotal();
        page.setTotalRows(total);
        //根据（总记录数-1）/每页展示的记录数+1  就是总页数
        Integer totalPage =(total-1)/page.getRowsPerPage()+1;
        page.setTotalPages(totalPage);
    //每页的数据:每页的数据时根据 select * from tab_role limit index,page.rowsPrePage
       //查询的开始位置index:第一则则从0开始，固定公式
        Integer index =(page.getCurrentPage()-1)*page.getRowsPerPage();
        List<Role> data =qxMapper.getAllRole(index,page.getRowsPerPage());
        page.setData(data);

    }

    @Override
    public void addQx(Role role) {
        qxMapper.addQx(role);
    }

    @Override
    public void delQx(String[] ids) {
        qxMapper.delQx(ids);
    }

    @Override
    public Role getRole(String id) {
        return qxMapper.getRole(id);

    }
}
